//@flow

/**
 * 导航栏 中间标题控件
 * 当参数为字符串，自动选择合适导航栏的自提颜色
 * 
 */

import React, { Component } from 'react';
import { 
    View,
    Text,
 } from 'react-native';
import { isLightColor } from '../util/common';
import { NAV_BAR_TITLE_STYLE,THEME_COLOR } from '../util/constant/ui';


export type Props = {
    title       :string|React.Component,
    
}
export type State = {}

export class NavBarTitleView extends Component <Props,State>{
    /**初始化props */
    static defaultProps : Props = {
        title	        :'',
        
    }
    /**初始化state */
    state :State = {}
    render(){
        const {title} = this.props;
        if(typeof this.props.title === 'string'){
            //简单的根据主题色决定字体的颜色
            return <Text style={[NAV_BAR_TITLE_STYLE,{color:isLightColor(THEME_COLOR)?'black':'white'}]}>{title}</Text>
        }else{
            return title
        }
    }
}